<template>
  <div class="app-container">
    <SearchForm
      v-show="showSearch"
      v-model="queryParams"
      :options="options.formOps"
      @onQuery="getList"
    >
    </SearchForm>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['inspectionPeriodName:create']"
          >新增</el-button
        >
      </el-col>

      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['system:user:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <Table
      ref="table"
      :auto-featch="true"
      :fetch-data="fetchData"
      :options="options.table"
    >
      <template #actionButton="{ row }">
        <el-button
          type="text"
          icon="Delete"
          style="color: red"
          @click="handleDel(row)"
          v-hasPermi="['inspectionPeriodName:delete']"
          >删除</el-button
        >
        <el-button type="text" @click="handleDetail(row)">查看</el-button>
      </template></Table
    >
    <el-dialog v-model="outerVisible" width="90%" title="巡检任务详情">
      <Inner ref="inner" :parentNode="parentNode"></Inner>
    </el-dialog>
    <DialogVform
      :formJson="formJson"
      ref="dialogVform"
      :title="'新增时段名称'"
      @onSubmit="onSubmit"
    ></DialogVform>
  </div>
</template>

<script setup>
import Table from "@/components/Table/index.vue";
import SearchForm from "@/components/searchForm/index";
import { apis as APIS } from "@/api/znxj/xjsjd.js";
import DialogVform from "@/components/dialogVform/index";

import formJson from "./components/options.json";
import { useAsyncData, useFormJsonNew } from "@/views/hooks/useAsyncData.js";
import Inner from "./components//inner.vue";
const inner = ref();
const parentNode = ref({});
const outerVisible = ref(false);
const handleDetail = (row) => {
  outerVisible.value = true;
  nextTick().then(() => {
    parentNode.value = row;
  });
};
const { proxy } = getCurrentInstance();

const ops = useFormJsonNew(formJson, {
  sort: [],
  sortable: [],
});
const options = reactive({
  table: ops,
  formOps: ops.filter((i) =>
    ["timeName", "routeName", "startTime", "endTime"].includes(i.prop)
  ),
});

const showSearch = ref(true);
const dialogVform = ref();
const table = ref();

const { fetchData, handleAdd, getList, queryParams, onSubmit, handleDel } =
  useAsyncData({
    APIS,
    formJson,
    dialogVform,
    table,
    proxy,
  });
onMounted(() => {});
</script>

<style lang="scss" scoped></style>
